/*
 * @Author: evan.wan
 * @Date:   2016-06-25 15:55:20
 */

'use strict';
define([
    '../../common/service',
    './tab/simpleElement',
    './tab/brandLogo',
    './tab/fontAndDesignElement',
], function(
    http,
    SimpleElement,
    BrandLogo,
    FontAndDesignElement
) {
    function me() {
        var self = this;
        this.init = function() {
            self.$root = $('.fmp-container');
            self.templateId = window.localStorage.getItem('goDetailTemplateId');
            self.templateName = window.localStorage.getItem('goDetailTemplateName');
            self.templateImg = window.localStorage.getItem('goDetailTemplateImg');
            self.render();
        }

        this.render = function() {
            //初始化头部
            self.initDetailHeadHtml();
            //初始化tab
            self.$root.find("div.ndp-tab-wrapper[name=plain-tab]").tabs({
                list: [I18N.getText('templateDetail', 'element'), I18N.getText('templateDetail', 'brandLogo'), I18N.getText('templateDetail', 'fontAndDesignElement')]
            }).on("TAB_CHANGE", function(e) {
                $("#tab-content" + e.originalEvent.data.index).removeClass("hidden").siblings().addClass("hidden");
                $(window).trigger('resize'); //触发 resize 事件,调整元素图片的位置
            }).val(0);
            self.event();
        }

        this.event = function() {
            //modal打开先请求元素数据
            //self.$root.find('#add-template-btn').off('click').on('click', $.proxy(self.openUploadDialog, self));
            //self.$root.find('.div-filter').off('click').on('click', $.proxy(self.initFilter, self));
            SimpleElement.init(self.templateId, function() {
                console.log(1);
            });
            BrandLogo.init(self.templateId, function() {
                console.log(2);
            });
            FontAndDesignElement.init(self.templateId, self.templateName, self.templateImg, function() {
                console.log(3);
            });

        }

        /**
         * 初始化模板详情页头部
         */
        self.initDetailHeadHtml = function() {
            self.$root.find('.template-detail-head-img img').attr('src', self.templateImg);
            self.$root.find('.template-detail-head-name').text(self.templateName);
            self.$root.find('.template-detail-head-category').text(window.localStorage.getItem('goDetailTemplateCategory'));
        }

        /**
         * { 上传模板modal }
         *
         * @method     openUploadDialog
         */
        this.openUploadDialog = function() {
            //new UploadDialogView().init(function() {
            //    self.getTemplateList();
            //});
        }



    }
    return new me();
});
